package com.obst.application.service;


import com.obst.data.ErrorCode;
import com.obst.data.pojo.UserInfo;
import com.obst.data.repository.UserRepository;

public class UserService {
	private UserRepository userRepository = new UserRepository();
	/*
	public User GetUser(Long accountId) {
		
		User user = userRepository.getUser(accountId);
		return user;
	}
	*/
	public UserInfo getUserInfoByEmail(String email) {
		UserInfo user = userRepository.getUserByEmail(email);
		return user;
	}
	
	public ErrorCode SetUser(UserInfo user) {
		if(user.getEmail() == null) {
			return ErrorCode.EMPTY_EMAIL;
		}
		if(userRepository.getUserByEmail(user.getEmail()).getEmail() == null) {
			userRepository.addUser(user);
			if(userRepository.getUserByEmail(user.getEmail()).getEmail() == null) {
				return ErrorCode.USER_ADD_FAIL;
			} else {
				return ErrorCode.SUCCESS;
			}			
		} else {
			return ErrorCode.DUPLICATE_EMAIL;
		}
	}
}
